/*
 * @文件描述:UI，只管理UI
 * @版本:
 * @作者:周晨阳
 * @Date:2021-10-31 09:57:02
 */
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <string>
#include "systemInfo.h"

using namespace std;
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(this, SIGNAL(signals_ChangeTitle(QString)), this, SLOT(solt_ChangeTitle(QString)));
    connect(this, SIGNAL(signals_ChangeRelValue(float)), this, SLOT(solt_ChangeRelValue(float)));
    connect(this, SIGNAL(signals_SetMemory(float)), this, SLOT(solt_SetMemory(float)));
    connect(this, SIGNAL(signals_SetDisk(float)), this, SLOT(solt_SetDisk(float)));
}

MainWindow::~MainWindow()
{
    delete ui;
}
/**
 * @brief :更改显示标题
 * @param {QString} title
 * @return {*}
 */
void MainWindow::onViewChangeTitle(QString title)
{
    emit signals_ChangeTitle(title);
    // QMetaObject::invokeMethod(this, [=]
    //                           { ui->title->setText(title); });
    // QMetaObject::invokeMethod((QObject *)ui->title, "setText", Qt::DirectConnection, Q_ARG(QString, title));
}
/**
 * @brief :
 * @param {float} relvalue
 * @return {*}
 */
void MainWindow::onViewChangeRelValue(float relvalue)
{

    emit signals_ChangeRelValue(relvalue);

    // QMetaObject::invokeMethod(this, [=]
    //                           {
    //                               ui->value->setText(QString::number(relvalue) + "%");
    //                               ui->value_dial->setValue((int)relvalue);
    //                           });
    // QMetaObject::invokeMethod((QObject *)ui->value, "setText", Qt::DirectConnection, Q_ARG(QString, QString::number(relvalue) + "%"));
    // QMetaObject::invokeMethod((QObject *)ui->value_dial, "setValue", Qt::DirectConnection, Q_ARG(int, (int)relvalue));
}
/**
 * @brief :
 * @param {float} relvalue
 * @return {*}
 */
void MainWindow::onViewSetMemory(float relvalue)
{

    emit signals_SetMemory(relvalue);

    // QMetaObject::invokeMethod(this, [=]
    //                           {
    //                               ui->MemprogressBar->setValue(relvalue);
    //                               ui->memLabel->setText(QString::number(relvalue) + "%");
    //                           });
    // QMetaObject::invokeMethod((QObject *)ui->MemprogressBar, "setValue", Qt::DirectConnection, Q_ARG(int, relvalue));
    // QMetaObject::invokeMethod((QObject *)ui->memLabel, "setText", Qt::DirectConnection, Q_ARG(QString, QString::number(relvalue) + "%"));
}
/**
 * @brief :
 * @param {float} relvalue
 * @return {*}
 */
void MainWindow::onViewSetDisk(float relvalue)
{

    emit signals_SetDisk(relvalue);

    // QMetaObject::invokeMethod(this, [=]
    //                           {
    //                               ui->DiskprogressBar->setValue(relvalue);
    //                               ui->diskLabel->setText(QString::number(relvalue) + "%");
    //                           });
    // QMetaObject::invokeMethod((QObject *)ui->DiskprogressBar, "setValue", Qt::DirectConnection, Q_ARG(int, relvalue));
    // QMetaObject::invokeMethod((QObject *)ui->diskLabel, "setText", Qt::DirectConnection, Q_ARG(QString, QString::number(relvalue) + "%"));
}
void MainWindow::solt_ChangeTitle(QString title)
{
    ui->title->setText(title);
}
void MainWindow::solt_ChangeRelValue(float relvalue)
{
    qDebug() << "onViewChangeRelValue:" << relvalue;
    ui->value->setText(QString::number(relvalue) + "%");
    ui->value_dial->setValue(relvalue);
}
void MainWindow::solt_SetMemory(float relvalue)
{
    qDebug() << "onViewSetMemory:" << relvalue;
    ui->MemprogressBar->setValue(relvalue);
    ui->memLabel->setText(QString::number(relvalue) + "%");
}
void MainWindow::solt_SetDisk(float relvalue)
{
    qDebug() << "onViewSetDisk:" << relvalue;
    ui->DiskprogressBar->setValue(relvalue);
    ui->diskLabel->setText(QString::number(relvalue) + "%");
}
